package cn.acewill.yxd.yunxundian.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.TextView;

import java.util.List;

import cn.acewill.yxd.yunxundian.R;
import cn.acewill.yxd.yunxundian.model.SchAddBean;

/**
 * Created by XXX on 2017/8/7.
 */

public class AddSchdeuleOEAdapter extends BaseAdapter{

    private Context context;
    private List<SchAddBean> list;
    private BtnCallBack btnCallBack;

    public AddSchdeuleOEAdapter(Context context,List<SchAddBean> list,BtnCallBack btnCallBack){
        this.context = context;
        this.list = list;
        this.btnCallBack = btnCallBack;
    }

    @Override
    public int getCount() {
        return  list==null?0:list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        viewHolder holder;
        if(convertView==null){
            convertView = LayoutInflater.from(context).inflate(R.layout.add_oe_schedule_view,parent,false);
            holder = new viewHolder();
            holder.schTitle = (TextView) convertView.findViewById(R.id.schTitle);
            holder.schMainTitleEdit = (TextView) convertView.findViewById(R.id.schMainTitleEdit);
            holder.sureTask = (Button) convertView.findViewById(R.id.sureTask);
            holder.cancel_btn = (Button) convertView.findViewById(R.id.cancel_btn);
            holder.taskTime = (TextView) convertView.findViewById(R.id.taskTime);
            convertView.setTag(holder);
        }else{
            holder = (viewHolder) convertView.getTag();
        }
        SchAddBean bean = list.get(position);
        holder.schTitle.setText(bean.getSchTypeStr());
        holder.taskTime.setText(bean.getSchStartTime().replace("T"," "));
        holder.schMainTitleEdit.setText(bean.getShopname());
        holder.sureTask.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                SchAddBean bean = list.get(position);
                btnCallBack.sureClick(bean,position);
            }
        });
        holder.cancel_btn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                SchAddBean bean = list.get(position);
                btnCallBack.cancleClick(bean,position);
            }
        });

        return convertView;
    }

    class viewHolder{
        TextView schTitle;
        TextView schMainTitleEdit;
        Button sureTask;
        Button cancel_btn;
        TextView taskTime;
    }

    public interface BtnCallBack{
        void sureClick(SchAddBean bean,int positon);
        void cancleClick(SchAddBean bean,int positon);
    }
}
